﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Permissions.EmployeeApp.Dto;
using Permissions.Models;

namespace Permissions.EmployeeApp
{
    public class EmployeeAppService : IEmployeeAppService
    {
        private readonly IRepository<Employee> _employeeRepository;

        public EmployeeAppService(IRepository<Employee> employeeRepository)
        {
            _employeeRepository = employeeRepository;
        }

        public void CreateEmployee(CreateEmployeeInput input)
        {
            var employee = new Employee { Name = input.Name, Department = input.Department };

            _employeeRepository.Insert(employee);
        }

        public void DeleteEmployee(EntityDto input)
        {
            _employeeRepository.Delete(input.Id);
        }

        public ListResultDto<EmployeeDto> GetEmployees()
        {
            var employees = _employeeRepository.GetAll();

            return new ListResultDto<EmployeeDto>(employees.MapTo<List<EmployeeDto>>());
        }

        public void UpdateEmployee(UpdateEmployeeInput input)
        {
            var employees = _employeeRepository.Get(input.Id);
            _employeeRepository.Update(input.MapTo(employees));
        }
    }
}
